<template>

  <div style="text-align: left">患者信息:
    <span style="font-size: 16px;background-color: beige;color: #42b983">
      姓名:{{ info.realName }}
      病历号:{{ info.caseNumber }}
      年龄:{{ info.age }}
      性别:{{ info.sex }}

    </span>
  </div>

  <hr/>
  <div style="text-align: left;font-weight: bolder">
    门诊确诊
  </div>
  <hr/>
  <div style="text-align: left">
    确诊信息录入
  </div>
  <el-form :model="formResult" label-width="auto" style="max-width: 100%">

  <el-form-item label="诊断结果">
    <el-input v-model="formResult.diagnosis" type="textarea" />
  </el-form-item>
  <el-form-item label="处理意见">
    <el-input v-model="formResult.cure" type="textarea" />
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitChecked">确诊提交</el-button>
    <el-button>重置输入</el-button>
  </el-form-item>
</el-form>

</template>

<script setup>
//定义病人信息数据
import {onMounted, reactive} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";

const info = reactive({
  realName: '',
  caseNumber: '',
  age: '',
  sex: ''
});
//定义诊断结果表单
const formResult=reactive({
  diagnosis:'',
  cure:''
});

//获取患者id
let item = sessionStorage.getItem("idKey");
let id=0;
if(item){
  let jsonItem=JSON.parse(item);
  id=jsonItem.id;
}

onMounted(()=>{
  getRegisterInfo();
})
/*定义函数加载病人信息*/
function getRegisterInfo() {

  axios.get("http://localhost/his/queryRegiserInfo/" + id)
      .then((response) => {
        info.realName = response.data.realName;
        info.caseNumber = response.data.caseNumber;
        info.age = response.data.age;
        info.sex = response.data.gender;
        //删除sessionStorage对象中保存的键值对

      })
      .catch((error) => {
        console.log(error);
      });
}
/*
* 发生ajax请求，保存确诊结果
* */
function submitChecked(){
  formResult.registerId=id; //formResult对象中不存在registerId，会自动添加
  axios.post("http://localhost/his/saveCheckedResult",formResult)
      .then((response) => {
        ElMessage(response.data.msg);
        //删除sessionStorage对象中保存的键值对
      })
      .catch((error) => {
        console.log(error);
      });
}
</script>

<style scoped>

</style>